package com.shopping.system.service.impl;

import com.shopping.common.entity.vo.UserVo;
import com.shopping.common.result.Result;
import com.shopping.system.mapper.UserMapper;
import com.shopping.system.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;

    /**
     * 查找用户
     * @param username
     * @return
     */
    @Override
    public Result<UserVo> findUserByUsername(String username) {
        UserVo userVo = userMapper.findUserByUsername(username);
        return Result.success(userVo);
    }

    /**
     * 添加用户
     * @param userVo
     * @return
     */
    @Override
    public Result<String> addUser(UserVo userVo) {
        Result<String> result = null;
        // 号码 账号 查重
        UserVo userVo1 = userMapper.findSameUserNameOrPhone(userVo);
        // 重复
        if(null !=userVo1) {
            result = Result.error("账号 手机号不能重复");
            return result;
        }

        // 未重复
        Integer tt = userMapper.adduser(userVo);
        result = Result.success("注册成功");
        if(tt<=0){
            result = Result.success("注册失败");
        }
        return result;
    }
}
